from app import db


class Food(db.Model):
    __tablename__ = 'food'

    id = db.Column(db.Integer, primary_key=True)
    category_id = db.Column(db.Integer,db.ForeignKey("food_category.id"),nullable=False,comment="分类id")  # 外键
    name = db.Column(db.String(100), nullable=False)
    price = db.Column(db.Numeric(10, 2), nullable=False)
    main_image = db.Column(db.String(100), nullable=False)
    summary = db.Column(db.String(2000), nullable=False,comment="描述")
    stock = db.Column(db.Integer,server_default="0",default=0, nullable=False,comment="今日库存量")
    tags = db.Column(db.String(200), nullable=False,comment="关键字，以‘,’连接")
    status = db.Column(db.Integer, nullable=False,server_default="1",default=1)  # 1.正常 0，已删除
    month_count = db.Column(db.Integer, nullable=False,server_default="0",default=0,comment="月销售数量")
    total_count = db.Column(db.Integer, nullable=False,server_default="0",default=0,comment="总销售数量")
    view_count = db.Column(db.Integer, nullable=False,server_default="0",default=0,comment="总浏览次数")
    comment_count = db.Column(db.Integer, nullable=False,server_default="0",default=0,comment="总评论量")
    updated_time = db.Column(db.DateTime, nullable=False)
    created_time = db.Column(db.DateTime, nullable=False)

    # 与StatDailyFood表的food_id相对应
    statFood = db.relationship("StatDailyFood",backref="food")

